package GUI;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;

import javax.swing.JFrame;
import javax.swing.JPanel;

import GUI.manager.VentanaFactory;
import GUI.manager.VentanaManager;
import core.model.Categoria;
import core.model.Empresa;
import core.model.Lista;
import core.model.Producto;
import core.model.Subcategoria;

public class panelCrearListaBusquedaCodigo extends javax.swing.JPanel implements
		ActionListener {

	public panelCrearListaBusquedaCodigo() {
		initComponents();
	}

	private void initComponents() {
		
		
		bTitulo = new javax.swing.JButton();
        etiquetaNick = new javax.swing.JLabel();
        botonSalir = new javax.swing.JButton();
        panelCentro = new javax.swing.JPanel();
        bAtras = new javax.swing.JButton();
        bBuscarCodigoBarras = new javax.swing.JButton();
        eCodigoBarras = new javax.swing.JLabel();
        tfCodigoBarras = new javax.swing.JTextField();
        bVolverLista = new javax.swing.JButton();
        bAgregarProducto = new javax.swing.JButton();
        eNombre = new javax.swing.JLabel();
        eSubcategoria = new javax.swing.JLabel();
        eCategoria = new javax.swing.JLabel();
        eUnidad = new javax.swing.JLabel();
        eCantidad = new javax.swing.JLabel();
        tfNombre = new javax.swing.JTextField();
        tfSubcategoria = new javax.swing.JTextField();
        tfCategoria = new javax.swing.JTextField();
        tfUnidad = new javax.swing.JTextField();
        tfCantidad = new javax.swing.JTextField();
        tfNumeroProductos = new javax.swing.JTextField();
        eNumeroProductos = new javax.swing.JLabel();
        eSuper = new javax.swing.JLabel();
        cbSuper = new javax.swing.JComboBox();
        etiquetaEntrada = new javax.swing.JLabel();
        bBusqueda = new javax.swing.JButton();
        bCrearLista = new javax.swing.JButton();
        bAyuda = new javax.swing.JButton();
        bHistorial = new javax.swing.JButton();
        bSugerencias = new javax.swing.JButton();
        bOpciones = new javax.swing.JButton();


		setBackground(new java.awt.Color(255, 255, 255));

		bTitulo.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/encabezadoMain.png")); // NOI18N
		bTitulo.setBorder(null);
		bTitulo.setBorderPainted(false);
		bTitulo.setBackground(new java.awt.Color(255, 255, 255));
		bTitulo.addActionListener(this);

		etiquetaNick.setBackground(new java.awt.Color(102, 102, 102));
		etiquetaNick.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		etiquetaNick.setText(panelPrincipal.nick);
		etiquetaNick.setToolTipText("");

		botonSalir.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/menu-salir.png")); // NOI18N
		botonSalir.setBorderPainted(false);
		botonSalir.addActionListener(this);
		botonSalir.setBackground(new java.awt.Color(255, 255, 255));

		panelCentro.setBackground(new java.awt.Color(255, 255, 255));

		bAtras.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/boton_atras.png")); // NOI18N
		bAtras.setBorder(null);
		bAtras.setBackground(new java.awt.Color(255, 255, 255));
		bAtras.addActionListener(this);

		eCodigoBarras.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eCodigoBarras.setForeground(new java.awt.Color(102, 102, 102));
		eCodigoBarras.setText("CODIGO DE BARRAS");

		
		tfCodigoBarras.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
	

		bVolverLista.setBackground(new java.awt.Color(255, 255, 255));
		bVolverLista.setFont(new java.awt.Font("Lucida Handwriting", 1, 14)); // NOI18N
		bVolverLista.setForeground(new java.awt.Color(243, 15, 120));
		bVolverLista.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonListaActual.png")); // NOI18N
		bVolverLista.setBorder(null);
		bVolverLista.addActionListener(this);
		
		bBuscarCodigoBarras.setIcon(new javax.swing.ImageIcon("src/GUI/resources/lupa.jpg")); // NOI18N
        bBuscarCodigoBarras.setBorder(null);
        bBuscarCodigoBarras.addActionListener(this);
        bBuscarCodigoBarras.setBackground(new java.awt.Color(255, 255, 255));

		bAgregarProducto.setBackground(new java.awt.Color(255, 255, 255));
		bAgregarProducto
				.setFont(new java.awt.Font("Lucida Handwriting", 1, 14)); // NOI18N
		bAgregarProducto.setForeground(new java.awt.Color(243, 15, 120));
		bAgregarProducto.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonAgregar.png")); // NOI18N
		bAgregarProducto.setBorder(null);
		bAgregarProducto.addActionListener(this);

		eNombre.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eNombre.setForeground(new java.awt.Color(102, 102, 102));
		eNombre.setText("NOMBRE");

		eSubcategoria.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eSubcategoria.setForeground(new java.awt.Color(102, 102, 102));
		eSubcategoria.setText("SUBCATEGORIA");

		eCategoria.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eCategoria.setForeground(new java.awt.Color(102, 102, 102));
		eCategoria.setText("CATEGORIA");

		eUnidad.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eUnidad.setForeground(new java.awt.Color(102, 102, 102));
		eUnidad.setText("UNIDAD");

		eCantidad.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eCantidad.setForeground(new java.awt.Color(102, 102, 102));
		eCantidad.setText("CANTIDAD");
		
		eSuper.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eSuper.setForeground(new java.awt.Color(102, 102, 102));
		eSuper.setText("SUPER/PRECIO");

		tfNombre.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tfNombre.setEditable(false);

		tfSubcategoria.setFont(new java.awt.Font("Calibri", 0, 13));
		tfSubcategoria.setEditable(false);
		
		tfCategoria.setFont(new java.awt.Font("Calibri", 0, 13));
		tfCategoria.setEditable(false);
		
		tfUnidad.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tfUnidad.setEditable(false);

		tfCantidad.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tfCantidad.setEditable(false);
		
		eNumeroProductos.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
        eNumeroProductos.setForeground(new java.awt.Color(102, 102, 102));
        eNumeroProductos.setText("NUMERO DE PRODUCTOS");

        tfNumeroProductos.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N

        org.jdesktop.layout.GroupLayout panelCentroLayout = new org.jdesktop.layout.GroupLayout(panelCentro);
        panelCentro.setLayout(panelCentroLayout);
        panelCentroLayout.setHorizontalGroup(
            panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panelCentroLayout.createSequentialGroup()
                .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(panelCentroLayout.createSequentialGroup()
                        .add(143, 143, 143)
                        .add(bAgregarProducto)
                        .add(55, 55, 55)
                        .add(bVolverLista))
                    .add(panelCentroLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(eSuper, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cbSuper, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .add(panelCentroLayout.createSequentialGroup()
                .addContainerGap()
                .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(panelCentroLayout.createSequentialGroup()
                        .add(eCodigoBarras, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(tfCodigoBarras)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(bBuscarCodigoBarras)
                        .add(97, 97, 97))
                    .add(panelCentroLayout.createSequentialGroup()
                        .add(eCantidad)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(tfCantidad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 135, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(eUnidad)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(tfUnidad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 135, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, panelCentroLayout.createSequentialGroup()
                        .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(panelCentroLayout.createSequentialGroup()
                                .add(eCategoria, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(tfCategoria, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, panelCentroLayout.createSequentialGroup()
                                .add(eNombre, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(tfNombre))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, panelCentroLayout.createSequentialGroup()
                                .add(bAtras)
                                .add(0, 0, Short.MAX_VALUE))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, panelCentroLayout.createSequentialGroup()
                                .add(eSubcategoria, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(tfSubcategoria, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .add(172, 172, 172))
                    .add(panelCentroLayout.createSequentialGroup()
                        .add(eNumeroProductos)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(tfNumeroProductos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 135, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(0, 0, Short.MAX_VALUE))))
        );
        panelCentroLayout.setVerticalGroup(
            panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panelCentroLayout.createSequentialGroup()
                .addContainerGap()
                .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(panelCentroLayout.createSequentialGroup()
                        .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                .add(eCodigoBarras)
                                .add(tfCodigoBarras, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(bBuscarCodigoBarras))
                        .add(36, 36, 36)
                        .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(tfNombre, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(eNombre))
                        .add(18, 18, 18)
                        .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(eCategoria)
                            .add(tfCategoria, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(18, 18, 18)
                        .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(eSubcategoria)
                            .add(tfSubcategoria, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(18, 18, 18)
                        .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(eCantidad)
                            .add(tfCantidad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(eUnidad)
                            .add(tfUnidad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(18, 18, 18)
                        .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(eSuper)
                            .add(cbSuper, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(18, 18, 18)
                        .add(panelCentroLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(eNumeroProductos)
                            .add(tfNumeroProductos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 19, Short.MAX_VALUE)
                        .add(bAgregarProducto))
                    .add(panelCentroLayout.createSequentialGroup()
                        .add(0, 0, Short.MAX_VALUE)
                        .add(bVolverLista)))
                .add(28, 28, 28)
                .add(bAtras)
                .addContainerGap())
        );
        
		etiquetaEntrada.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		etiquetaEntrada.setForeground(new java.awt.Color(243, 15, 120));
		etiquetaEntrada.setText("BIENVENIDO A LISTA DE LA COMPRA MAKER ");

		bBusqueda.setBackground(new java.awt.Color(255, 255, 255));
		bBusqueda.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bBusqueda.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonBusqueda.png")); // NOI18N
		bBusqueda.setToolTipText("");
		bBusqueda.setBorderPainted(false);
		bBusqueda.addActionListener(this);

		bCrearLista.setBackground(new java.awt.Color(255, 255, 255));
		bCrearLista.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bCrearLista.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonCrearLista.png")); // NOI18N
		bCrearLista.setBorderPainted(false);
		bCrearLista.addActionListener(this);

		bAyuda.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bAyuda.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonAyuda.png")); // NOI18N
		bAyuda.setBorderPainted(false);
		bAyuda.addActionListener(this);
		bAyuda.setBackground(new java.awt.Color(255, 255, 255));

		bHistorial.setBackground(new java.awt.Color(255, 255, 255));
		bHistorial.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bHistorial.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonHistorial.png")); // NOI18N
		bHistorial.setBorderPainted(false);
		bHistorial.addActionListener(this);

		bSugerencias.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bSugerencias.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonSugerencias.png")); // NOI18N
		bSugerencias.setBorderPainted(false);
		bSugerencias.setBackground(new java.awt.Color(255, 255, 255));

		bOpciones.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		bOpciones.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonOpciones.png")); // NOI18N
		bOpciones.setBorderPainted(false);
		bOpciones.addActionListener(this);

		org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
				this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(layout
						.createSequentialGroup()
						.addContainerGap()
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(layout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.TRAILING)
										.add(bCrearLista,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												157,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(bBusqueda,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												155,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(bHistorial,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												157,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(bSugerencias,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												157,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(bOpciones,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												157,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
								.add(org.jdesktop.layout.GroupLayout.TRAILING,
										bAyuda,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										157,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
						.add(27, 27, 27)
						.add(panelCentro,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE).add(15, 15, 15))
				.add(layout
						.createSequentialGroup()
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(layout.createSequentialGroup()
										.add(96, 96, 96).add(bTitulo)
										.add(44, 44, 44).add(botonSalir))
								.add(layout
										.createSequentialGroup()
										.add(84, 84, 84)
										.add(etiquetaEntrada)
										.add(46, 46, 46)
										.add(etiquetaNick,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												280,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
						.addContainerGap(
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE)));
		layout.setVerticalGroup(layout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(layout
						.createSequentialGroup()
						.add(6, 6, 6)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(bTitulo,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										104,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
								.add(botonSalir))
						.add(6, 6, 6)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(etiquetaEntrada).add(etiquetaNick))
						.add(18, 18, 18)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(layout
										.createSequentialGroup()
										.add(bBusqueda,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bCrearLista,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bHistorial,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bSugerencias,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bOpciones,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(bAyuda,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												41,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(0, 0, Short.MAX_VALUE))
								.add(panelCentro,
										org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
										org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)).addContainerGap()));
	}
	
	private Empresa obtenerEmpresasByCodigoEmpresa(int codigo_empresa) {
		// TODO Auto-generated method stub
		VentanaManager ventanaManager = VentanaFactory.getInstance();
		Empresa empresa = ventanaManager.findCodigoEmpresa(codigo_empresa);
		return empresa;
	}
	
	private Empresa obtenerPrecio (int codigo_empresa, String codigo_producto) {
		VentanaManager ventanaManager = VentanaFactory.getInstance();
		Empresa empresa = ventanaManager.findPrecio(codigo_empresa, codigo_producto);
		return empresa;
	}
	
	private List<Empresa> obtenerEmpresasByCodigoProducto(String codigo_barras) {
		// TODO Auto-generated method stub
		VentanaManager ventanaManager = VentanaFactory.getInstance();
		List<Empresa> empresas = ventanaManager.findByCodigoProducto(codigo_barras);
		return empresas;
		
	}

	private Producto bucarProducto(String codigo_barras) {
		Producto producto;
		VentanaManager ventanaManager = VentanaFactory.getInstance();
		producto = ventanaManager.findBy(codigo_barras);
		return producto;
	}

	private Categoria buscarCategoria(int codigo_categoria) {
		Categoria categoria;
		VentanaManager ventanaManager = VentanaFactory.getInstance();
		categoria = ventanaManager.getCategoriaByCode(codigo_categoria);
		return categoria;
	}

	private Subcategoria buscarSubcategoria(int codigo_subcategoria) {
		Subcategoria subcategoria;
		VentanaManager ventanaManager = VentanaFactory.getInstance();
		subcategoria = ventanaManager
				.getSubcategoriaByCode(codigo_subcategoria);
		return subcategoria;
	}
	

	private javax.swing.JButton bAgregarProducto;
    private javax.swing.JButton bAtras;
    private javax.swing.JButton bAyuda;
    private javax.swing.JButton bBusqueda;
    private javax.swing.JButton bCrearLista;
    private javax.swing.JButton bHistorial;
    private javax.swing.JButton bOpciones;
    private javax.swing.JButton bSugerencias;
    private javax.swing.JButton bTitulo;
    private javax.swing.JButton bVolverLista;
    private javax.swing.JButton botonSalir;
    private javax.swing.JTextField tfCategoria;
    private javax.swing.JTextField tfSubcategoria;
    private javax.swing.JComboBox cbSuper;
    private javax.swing.JButton bBuscarCodigoBarras;
    private javax.swing.JLabel eCantidad;
    private javax.swing.JLabel eCategoria;
    private javax.swing.JLabel eCodigoBarras;
    private javax.swing.JLabel eNumeroProductos;
    private javax.swing.JLabel eNombre;
    private javax.swing.JLabel eSubcategoria;
    private javax.swing.JLabel eSuper;
    private javax.swing.JLabel eUnidad;
    private javax.swing.JLabel etiquetaEntrada;
    private javax.swing.JLabel etiquetaNick;
    private javax.swing.JTextField tfCodigoBarras;
    private javax.swing.JPanel panelCentro;
    private javax.swing.JTextField tfCantidad;
    private javax.swing.JTextField tfNombre;
    private javax.swing.JTextField tfUnidad;
    private javax.swing.JTextField tfNumeroProductos;
    private String supermercado;
	private JFrame actual;
	private JPanel estePanel = this;
	private int ant;

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == bSugerencias) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelSugerencias());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}

		if (e.getSource() == bBusqueda) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelBusqueda());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}

		if (e.getSource() == bHistorial) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelHistorial());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bOpciones) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelOpciones());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bAyuda) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelAyuda());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bVolverLista) {
			
			if (ant == 1) {
				actual = (JFrame) UtilidadesGUI
						.getContenedorPrincipal(estePanel);
				actual.getContentPane().remove(0);
				actual.getContentPane().add(new panelCrearListaEconomica(0));
				actual.setPreferredSize(new Dimension(850, 630));
				actual.pack();
				actual.repaint();
				UtilidadesGUI.CentrarPantalla(actual);
			}

		}
		if (e.getSource() == bAtras) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelCrearListaBusqueda());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bTitulo) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelPrincipal());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == botonSalir) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelSalir(11));
			actual.setPreferredSize(new Dimension(610, 330));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bAgregarProducto) {
			VentanaManager ventanaManager = VentanaFactory.getInstance();
			Lista lista =ventanaManager.findbyTitulo(panelCrearLista.titulo);
			StringTokenizer token=new StringTokenizer(cbSuper.getSelectedItem().toString(), " ");
			Empresa empresa=ventanaManager.findByNombreEmpresa(token.nextToken());
			ventanaManager.insertProductoLista(empresa.getCodigo_empresa(), tfCodigoBarras.getText(), lista.getCodigo_lista(),Integer.parseInt(tfNumeroProductos.getText()));
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelCrearListaBusquedaLector());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

			

		}
		if (e.getSource() == bBuscarCodigoBarras) {
			String codigo_barras = tfCodigoBarras.getText();
			Producto producto = bucarProducto(codigo_barras);
			Subcategoria subcategoria = buscarSubcategoria(producto.getCodigo_subcategoria());
			Categoria categoria = buscarCategoria(subcategoria.getCodigo_categoria());
			
			tfNombre.setText(producto.getNombre());

			tfCategoria.setText(categoria.getNombre());

			tfSubcategoria.setText(subcategoria.getNombre());
			tfCantidad.setText(String.valueOf(producto.getCantidad()));
			tfUnidad.setText(producto.getUnidad());
			
			// RELLENAR COMBOBOX
			List<String> listaNombresEmpresas = new ArrayList<String>();
			List<Empresa> empresas1 = obtenerEmpresasByCodigoProducto(codigo_barras);
						
			Iterator<Empresa> iterator = empresas1.iterator();
			while (iterator.hasNext()) {
				Empresa empresa = iterator.next();
				listaNombresEmpresas.add(String.valueOf(obtenerEmpresasByCodigoEmpresa(empresa.getCodigo_empresa()).getNombre())+"  "+obtenerPrecio(empresa.getCodigo_empresa(), codigo_barras).getPrecio());
			}
			String[] empresasArrayString = new String[listaNombresEmpresas.size()];
			listaNombresEmpresas.toArray(empresasArrayString);

			cbSuper.setModel(new javax.swing.DefaultComboBoxModel<String>(
					empresasArrayString));
			// FIN
			cbSuper.setEnabled(true);
			cbSuper.setSelectedIndex(0);

			

		}

	}
	

}
